package main

import (
	"fmt"
	"sort"
)

func main() {
	//slice和map都可以用range遍历

	var a map[int]string
	fmt.Println(a)

	var b map[int]string = make(map[int]string)
	fmt.Println(b)

	c := make(map[int]string)
	fmt.Println(c)

	c[1] = "ok"
	c[2] = "lu"
	fmt.Println(c)
	delete(c, 1)
	fmt.Println(c)

	var d map[int]map[int]string
	fmt.Println(d)

	e := make(map[int]map[int]string)
	e[1] = make(map[int]string)
	e[1][1] = "ok"
	fmt.Println(e)

	f := make(map[int]map[int]string)
	ff, ok := f[2][1]
	if !ok {
		f[2] = make(map[int]string)
		fmt.Println("empty")
	} else {
		fmt.Println(ff)
	}

	g := make([]map[int]string, 5)
	for i := range g {
		g[i] = make(map[int]string, 1)
		g[i][1] = "ok"
		fmt.Println(g[i])
	}
	fmt.Println(g)
	for i, _ := range g {
		g[i] = make(map[int]string, 1)
		g[i][1] = "ok"
		fmt.Println(g[i])
	}
	fmt.Println(g)

	//排序
	h := map[int]string{1: "a", 2: "b", 3: "c", 4: "d"}
	s := make([]int, len(h))
	j := 0
	for k, _ := range h {
		s[j] = k
		j++
	}
	sort.Ints(s)
	fmt.Println(s)
}
